﻿#region

using System.Collections.Generic;
using System.Linq;
using Lab.DataContext.DataContext;
using Lab.Server.Domain;

#endregion

namespace Lab.Server.Infrastructure {
    public class KindOfActivityRepository : Repository<KindOfActivity, kind_of_activity> {
        public KindOfActivityRepository(IDataContext dataContext) : base(dataContext) {}

        protected override kind_of_activity TranslateToDataObject(KindOfActivity domainObject) {
            return new kind_of_activity { kind_of_activity_description = domainObject.Description };
        }

        public virtual kind_of_activity_for_employer GetKindOfActivityForEmployer(KindOfActivity kindOfActivity) {
            return new kind_of_activity_for_employer {
                                                         kind_of_activity = GetKindOfActivityDataObject(kindOfActivity)
                                                     };
        }

        public kind_of_activity GetKindOfActivityDataObject(KindOfActivity kindOfActivity) {
            return DataContext.GetKindOfActivities().Single(_ => _.kind_of_activity_id == kindOfActivity.Id);
        }

        public KindOfActivity TranslateToDomain(kind_of_activity kindOfActivity) {
            return new KindOfActivity {
                                          Id = kindOfActivity.kind_of_activity_id,
                                          Description = kindOfActivity.kind_of_activity_description
                                      };
        }

        public List<KindOfActivity> GetKindOfActivities() {
            return DataContext.GetKindOfActivities().ConvertAll(TranslateToDomain);
        }
    }
}